import React, { useState, useEffect } from 'react'
import { View, Image } from '@tarojs/components'
import Taro, { useDidShow } from '@tarojs/taro'
import api from '../../http/api'


import './index.less'

export default (props: any) => {
  const info: any = Taro.getStorageSync('info')
  const uSchoolId = info ? JSON.parse(info).userInfo.uSchoolId : 0
  const [list, setList] = useState([{ "id": 33, "uSchoolId": 1, "src": "https://static.zhongningwenhua.com/uniSchool/upload/a59b217e026c3a4df82ef88eaab02699.png", "title": "一展拼搏活力，乐在趣味赛场", "intro": "湖科活力校园", "activeTime": "2020-12-19T10:30:30.000Z", "address": "湖北科技学院行政楼团辅导室", "content": "<p><img src=\"https://static.zhongningwenhua.com/uniSchool/upload/e6c3ceedf0399d064366621a0fa147e1.png\" style=\"max-width:100%;\" width=\"100%\"><br></p>", "type": 1, "manageId": 11, "isGrounding": 1, "publishTime": "2020-12-24T04:31:59.000Z", "ord": 0 }])
  const toDetail = (item: any) => {
    Taro.navigateTo({
      url: `/pages/activeDetail/index?id=${item.id}`
    })
  }
  useDidShow(() => {
    api.version().then((res:any)=>{
      const version = res.data
      if(version ===1){
        api.activeList({
          title: props.title,
          uSchoolId
        }).then((res: any) => {
          setList(res.data.list)
        })
      }
    })
  })
  // useEffect(()=>{
  //   api.activeList({
  //     title:props.title,
  //     uSchoolId
  //   }).then((res:any)=>{
  //     setList(res.data.list)
  //   })
  // },[props.title])
  return (
    <View className='business'>
      {
        list.map((item, i) => (
          <View className='list' key={i} onClick={() => { toDetail(item) }}>
            <Image className='img' src={item.src} ></Image>
            <View className='title'>{item.title}</View>
            <View className='cont'>{item.intro}</View>
          </View>
        ))
      }

    </View>
  )
}
